package com.cloudfast.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.cloudfast.config.property.StorageProperty;
import com.cloudfast.config.property.c.DefaultProperty;
import com.cloudfast.config.property.c.LocalProperty;
import com.cloudfast.config.property.c.MinioProperty;
import com.cloudfast.manager.FileStorageManager;
import com.cloudfast.manager.impl.FtpStorageManagerImpl;
import com.cloudfast.manager.impl.LocalStorageManagerImpl;
import com.cloudfast.manager.impl.MinioStorageService;
import com.cloudfast.manager.impl.SftpStorageManagerImpl;

/**
 * 文件上传启动配置类
 *
 * @author liuyw
 */
@Configuration
public class StorageConfiguration {

    @Autowired
    private StorageProperty storageConfig;

    @Autowired
    private DefaultProperty defaultProperty;

    @Autowired
    private LocalProperty localProperty;

    @Autowired
    private MinioProperty minioProperty;

    @Bean
    @ConditionalOnProperty(name = "cloudfast.storage.type", havingValue = "sftp")
    public FileStorageManager sftpStorageManager() {
        return new SftpStorageManagerImpl(defaultProperty, this.storageConfig.getMaxFileSize());
    }

    @Bean
    @ConditionalOnProperty(name = "cloudfast.storage.type", havingValue = "ftp")
    public FileStorageManager ftpStorageManager() {
        return new FtpStorageManagerImpl(defaultProperty, this.storageConfig.getMaxFileSize());
    }

    @Bean
    @ConditionalOnProperty(name = "cloudfast.storage.type", havingValue = "local")
    public FileStorageManager localStorageManager() {
        return new LocalStorageManagerImpl(localProperty, this.storageConfig.getMaxFileSize());
    }

    @Bean
    @ConditionalOnProperty(name = "cloudfast.storage.type", havingValue = "minio")
    public FileStorageManager minioStorageManager() {
        return new MinioStorageService(minioProperty, this.storageConfig.getMaxFileSize());
    }

}
